package cn.laixueit.controller;

import cn.laixueit.base.R;
import cn.laixueit.pojo.Source;
import cn.laixueit.service.SourceService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author duxiang
 * @date 2023/12/27 14:46
 */
@RestController
@RequestMapping("/source")
public class SourceController {
    @Resource
    private SourceService sourceService;

    @PostMapping("page/{page}/{size}")
    public R page(@PathVariable("page")Integer page, @PathVariable("size")Integer size,
                  @RequestBody Source source){
        Page<Source> sourcePage = new Page<>();
        return sourceService.sourcePage(sourcePage,source);
    }

    @PostMapping("saveSource")
    public R saveSource(@RequestBody Source source){
        sourceService.saveSource(source);
        return R.ok();
    }

    @DeleteMapping("removeSource/{id}")
    public R removeSource(@PathVariable("id")String id){
        sourceService.removeSource(id);
        return R.ok();
    }

    @GetMapping("findSource/{id}")
    public R findSource(@PathVariable("id")String id){
        Source source = sourceService.findSource(id);
        return R.ok().put("obj",source);
    }

}
